package com.wxjfkg.workflow.impl;

import org.activiti.engine.delegate.DelegateExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fivestar.util.str.StringUtils;
import com.fivestar.xbk.service.XbkWorkOrderService;
import com.fivestar.xbk.service.vo.XbkConstants;
import com.fivestar.xbk.service.vo.XbkWorkOrderDto;
import com.wxjfkg.workflow.BeforeEndTaskService;

@Service("workorderFailTaskService")
public class WorkorderFailTaskServiceImpl implements BeforeEndTaskService {

	public Logger logger = LoggerFactory.getLogger(WorkorderFailTaskServiceImpl.class);
	
	@Autowired
	private XbkWorkOrderService xbkWorkOrderService;
	
	@Override
	@Transactional(value="txTranManager")
	public void execute(DelegateExecution execution) throws Exception {
		String businessKey = execution.getProcessBusinessKey();
		if(!StringUtils.isEmpty(businessKey)){
			XbkWorkOrderDto workOrderDto = new XbkWorkOrderDto();
			workOrderDto.setOrderCode(businessKey);
			workOrderDto.setOpStatus(XbkConstants.ORDER_STATE.CANCEL);
			Boolean flag = xbkWorkOrderService.updateOrderByCode(workOrderDto);
			if(flag){
				logger.info("工单编号[orderId]="+businessKey+"的工单状态更新成功");
			}else{
				logger.error("工单编号[orderId]="+businessKey+"的工单状态更新失败");
			}
		}else{
			logger.error("工单编号[orderId]为空");
		}

	}

}
